import { Button } from 'antd';
import { action, observable } from "mobx";
import * as React from 'react';
import DialogStore from ".";
import { WeaLocaleProvider } from "ecCom";
const getLabel = WeaLocaleProvider.getLabel;

export default class AddFixphareStore extends DialogStore {

    @observable browserDatas = [];
    @observable type;
    @observable browserType;
    @observable browserTitile;
    @observable tabs;
    @observable oraginValue; // 下拉框的值
    @observable inputType = 'INPUT';
    @observable isMultCheckbox = false;
    @observable columns = [{
        com: [
            { type: this.inputType, key: 'selectName', readonly: 'readonly' }
        ],
        dataIndex: 'selectName',
        title: '固定解析文字',
        width: '70%',

    }
        // , {
        //     com: [
        //         { type: 'radio', key: 'default' }
        //     ],
        //     dataIndex: 'default',
        //     title: getLabel('502868','默认'),
        //     width: '20%',
        //     key:'default',
        //     checkType: 'radio',
        // }, {
        //     com: [
        //         { type: 'checkbox', key: 'unuse' }
        //     ],
        //     dataIndex: 'unuse',
        //     title:getLabel('502869','封存'),
        //     width: '20%',
        // }
    ];

    @observable datas = [];
    constructor() {
        super();
        this.style = { width: 520, height: 300 };
        this.title = '固定解析维护';
        this.buttons = [<Button key="cancel" type="primary" onClick={this.hide}>{getLabel(31129, '取消')}</Button>];
    }
    @action
    initOptions = (datas) => {
        // 设置输入框类型
        this.columns = [{
            com: [
                { type: 'input', key: 'selectName', readonly: 'readonly' }
            ],
            dataIndex: 'selectName',
            title: '固定解析文字',
            width: '70%',
        }]
        this.datas = datas;

        if (datas) {
            datas = datas.filter(s => s.selectValue).map(d => ({ id: d.selectValue, name: d.selectName }))
        } else {
            datas = [];
        }
        this.browserDatas = datas;
    }

    @action
    initBrowserOptions = (datas) => {
        this.datas = datas;

        if (datas) {
            datas = datas.filter(s => s.selectValue).map(d => ({ id: d.selectValue, name: d.selectName }))
        } else {
            datas = [];
        }
        this.browserDatas = datas;
    }

    @action
    onChange = (datas) => {
        this.datas = datas.map((d, index) => ({
            //default: "",
            selectValue: index,
            //unuse: "",
            ...d
        }));
    }

    @action
    befordAdd = (datas, addData) => {
        const bt = ((this.type || [])[1] || {}).value;
        if (this.fieldType == 'browser' && !(bt == '2' || bt == '19' || bt == '290')) {
            this.showBrowserModal();
            return;
        } else if (this.fieldType == 'select') {
            return this.oraginValue.map(data => {
                return data;
            });
        }
        return datas.map(data => {
            return data;
        });
    }

    @action
    showBrowserModal() {

        if (this.browserInstance) {
            this.browserInstance.openModal();
        }
    }

    @action
    changeValue = (newValue, valueSpan, valueObj) => {

        const value = valueObj.map(d => ({ selectValue: d.id, randomkey: d.id, selectName: d.name }));
        this.datas = value;
    }

    @action
    browserSetting = () => {
        const range = this.sheet.getCell(this.row, this.col);
        this.type = range.cellType().fieldType;
        this.browserType = this.type[1].value;
        if (this.type.length == 2) {

            this.browserTitile = this.type[1].valueSpan;
        } else {
            if (this.type[1]["valueObj"]) {
                this.browserTitile = this.type[1]["valueObj"][0].name;
            } else {
                this.browserTitile = this.type[1].valueSpan;
            }

        }
        // 设置输入框类型
        if (this.browserType == 2) {
            this.columns = [{
                com: [
                    { type: 'DATEPICKER', key: 'selectName' }
                ],
                dataIndex: 'selectName',
                title: getLabel('502867', '可选项文字'),
                width: '70%',
            }]
        } else if (this.browserType == 19) {
            this.columns = [{
                com: [
                    { type: 'TIMEPICKER', key: 'selectName' }
                ],
                dataIndex: 'selectName',
                title: getLabel('502867', '可选项文字'),
                width: '70%',
            }]
        } else if (this.browserType == 290){
            this.columns = [{
                com: [
                    { type: this.inputType, key: 'selectName' }
                ],
                dataIndex: 'selectName',
                title: '固定解析文字',
                width: '70%',

            }]
        }else {
            this.columns = [{
                com: [
                    { type: this.inputType, key: 'selectName', readonly: 'readonly' }
                ],
                dataIndex: 'selectName',
                title: '固定解析文字',
                width: '70%',

            }]
        }

        // 由于单选都需要多选，所以需要进行类型转换
        if (this.browserType == 1)
            this.browserType = 17;
        if (this.browserType == 4)
            this.browserType = 57;
        if (this.browserType == 7)
            this.browserType = 18;
        if (this.browserType == 8)
            this.browserType = 135;
        if (this.browserType == 9)
            this.browserType = 37;
        if (this.browserType == 87)
            this.browserType = 184;
        if (this.browserType == 161)
            this.browserType = 162;
        if (this.browserType == 164)
            this.browserType = 194;
        if (this.browserType == 165)
            this.browserType = 166;
        if (this.browserType == 167)
            this.browserType = 168;
        if (this.browserType == 169)
            this.browserType = 170;
        if (this.browserType == 256)
            this.browserType = 257;
        if (this.browserType == '161' || this.browserType == '162' || this.browserType == '256' || this.browserType == '257') {
            this.dataParams = { ...this.dataParams, type: (this.type[2] || {}).value }
        } else {
            this.dataParams ={};
        }

        if (this.browserType == '58' || this.browserType =='25' || this.browserType =='13' || this.browserType =='63'|| this.browserType =='263'|| this.browserType =='34') {
            this.isMultCheckbox = true;
        } else {
            this.isMultCheckbox = false;
        }
        if (this.browserType == '4' || this.browserType == '57' || this.browserType == '167' || this.browserType == '168') {
            this.tabs = {
                tabs: [{
                    "key": "2",
                    "name": getLabel('505968', '组织结构'),
                    "dataURL": null,
                    "dataParams": null,
                    "isSearch": false,
                    "showOrder": 0,
                    "selected": false
                }, {
                    "key": "1",
                    "name": getLabel('505969', '按列表'),
                    "dataURL": null,
                    "dataParams": {
                        "list": "1"
                    },
                    "isSearch": true,
                    "showOrder": 0,
                    "selected": false
                }]
            };
        } else if (this.browserType == '164' || this.browserType == '169' || this.browserType == '170' || this.browserType == '194') {
            this.tabs = {
                tabs: [{
                    "key": "2",
                    "name": getLabel('505968', '组织结构'),
                    "dataURL": null,
                    "dataParams": null,
                    "isSearch": false,
                    "showOrder": 0,
                    "selected": false
                }, {
                    "key": "1",
                    "name": getLabel('505969', '按列表'),
                    "dataURL": null,
                    "dataParams": {
                        "list": "1"
                    },
                    "isSearch": true,
                    "showOrder": 0,
                    "selected": false
                }]
            };
        } else {
            this.tabs = {};
        }
    }
}